﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;

namespace WebApplication{

    public partial class aspNetBase : System.Web.UI.Page{
        private delegate int _CaculateRef(int num1, int num2);
        private _CaculateRef _caculateMethod;
        private WebApplication.Product _productObj;

        protected void Page_Load(object sender, EventArgs e){
            PreLoad();
        }

        protected void BtnGetResult_OnClick(object sender, EventArgs e) { 
            if(RadBtnListCalculateMethod.SelectedItem != null){
                if (RadBtnListCalculateMethod.SelectedItem.Text == "Plus")
                    _caculateMethod = PublicMethods.PlusTwoNums;
                if (RadBtnListCalculateMethod.SelectedItem.Text == "Subtract") 
                    _caculateMethod = PublicMethods.SubtractTwoNums;
                if (TxtBoxNum1.Text != null && TxtBoxNum1.Text != "" && TxtBoxNum2.Text != null && TxtBoxNum2.Text != "")
                  lblCalculateResult.Text = "The result is: " + _caculateMethod(Convert.ToInt32(TxtBoxNum1.Text), Convert.ToInt32(TxtBoxNum2.Text));
                else
                    lblCalculateResult.Text = "Please input value.";
            }
            else
                 lblCalculateResult.Text = "Please select method.";
        }

        private void PreLoad() {
            PreLoadProduct();
        
        }

        private void PreLoadProduct() {
            _productObj = new Product(932.50, "ASUS U31F");
            lblProduct1Name.Text = _productObj.Name;
            lblProduct1Price.Text = _productObj.Price.ToString();
            _productObj = new Product(125.30, "BENQ GL2030");
            Product productCastRef = _productObj;
            lblProduct2Name.Text = productCastRef.Name;
            lblProduct2Price.Text = productCastRef.Price.ToString();
        }

        private void CreateListProduct() {
            ArrayList productArrayList = new ArrayList();    
            List<Product> productList = new List<Product>();
            
            //ArrayList can store different types of objects
            productArrayList.Add(new Product(932.50, "ASUS U31F"));
            productArrayList.Add(new Product(125.30, "BENQ GL2030"));
            productArrayList.Add("Electronical Products.");

            //List only sotres one type of objects
            productList.Add(new Product(932.50, "ASUS U31F"));
            productList.Add(new Product(125.30, "BENQ GL2030"));
        }

    }
   
    
}